<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>项目审核（学院老师-学段）</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=10,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
    <link rel="stylesheet" type="text/css" href="/lib/layui/layui/css/layui.css"/>
    <script type="text/javascript" src="/js/news/jquery-1.9.1.js"></script>
    <script src="/js/base/base.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../js/jquery/jquery.cookie.js"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript"
            charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.js"></script>
    <script type="text/javascript" src="/lib/layui/layui/layui.all.js"></script>
</head>
<style>
    .mbox {
        padding: 8px
    }

    .item img {
        height: 40px;
    }

    .btn {
        height: 37px;
    }

    .btn button {
        float: right;
    }

    .information {
        background: #e8f4fc;
        height: 30px;
        line-height: 30px;
    }

    .add {
        height: 30px;
    }

    .layui-form-item {
        margin-bottom: 5px;
    }

    .layui-input-inline {
        width: 300px !important;
    }

    .openFile input[type=file] {
        position: absolute;
        top: 0;
        right: 0;
        bottom: 0;
        left: 0;
        width: 100%;
        height: 18px;
        z-index: 99;
        opacity: 0;
    }

    .btn .layui-btn {
        margin-left: 10px;
    }

    .typeIpt {
        line-height: 30px;
        margin-left: 10px;
    }

    .layui-table-tool {
        display: none;
    }

    .layui-table-view i{
        width: 18px;
        height: 18px;
        margin-top: 5px;
    }
</style>
<body>
<div class="mbox">
    <div class="item">
        <img src="../img/yeji.png" alt="" style="margin: 0 5px 0 20px;"> <span
            style="font-size: 22px;display: inline-block;vertical-align: middle;">项目申报审核-学段科研员</span>
    </div>
    <hr class="layui-bg-blue">
    <div class="btn" style="display: inline-flex;">
        <span class="typeIpt layui-form">
            <input type="radio" checked lay-filter="status" value="0" name="status" title="未审核"/>&nbsp;
            <input type="radio" lay-filter="status" value="1" name="status" title="通过"/>&nbsp;
            <input type="radio" lay-filter="status" value="2" name="status" title="退回"/>&nbsp;
            <input type="radio" lay-filter="status" value="8" name="status" title="不通过"/>&nbsp;
        </span>
        <form class="layui-form" action="">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">研究领域</label>
                    <div class="layui-input-inline">
                        <select name="research" lay-verify="required" lay-search="">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">学段</label>
                    <div class="layui-input-inline">
                        <select name="sectionType" lay-verify="required" lay-search="">
                            <option value="">请选择</option>
                        </select>
                    </div>
                </div>
                <button type="button" class="layui-btn search">查询</button>
            </div>
        </form>
    </div>
    <table  id="test" lay-filter="test"></table>
</div>
</body>
</html>
<script type="text/html" id="barDemo">
    {{#  if(d.teacheerStatus == 0){ }}
    <a class="layui-btn layui-btn-xs layui-btn-warm" lay-event="look">查看</a>
    <a class="layui-btn layui-btn-xs" value="1" lay-event="operate">通过</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" value="2" lay-event="operate">退回</a>
    <a class="layui-btn layui-btn-xs layui-btn-danger" value="8" lay-event="operate">不通过</a>
    {{#  } }}
</script>
<script>
    layui.use(['table', 'form', 'laydate', 'upload'], function () {
        var table = layui.table,
            form = layui.form,
            laydate = layui.laydate,
            upload = layui.upload;
        var leaderStatus = 1;
        form.render();
        var taId;
            var tableData=table.render({
                elem: '#test'
                , url: '/rpmTopic/selectTopicT'
                , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                , defaultToolbar: ['']
                , where:{
                    status:0,
                    sDirectorLeaderStatus:"1",
                    deptId: $.cookie('deptId')

                }
                , title: '用户数据表'
                , cols: [[
                    {type: 'checkbox', fixed: 'left'},
                    {field: 'planName', title: '计划名称'}
                    , {field: 'topicName', title: '项目名称'}
                    , {field: 'topicType', title: '项目类别',}
                    , {field: 'research', title: '研究领域'}
                    , {field: 'sDirectorLeaderStatus', title: '学校科研室主任审批状态',templet: function(d){
                            if(d.sDirectorLeaderStatus=='0'){
                                return '未审核'
                            }else if(d.sDirectorLeaderStatus=='1'){
                                return '通过'
                            }else if(d.sDirectorLeaderStatus=='2'){
                                return '退回'
                            }else if(d.sDirectorLeaderStatus=='8'){
                                return '不通过'
                            }else {
                                return''
                            }
                        }}
                    , {field: 'teacheerStatus', title: '学院老师审批状态',templet: function(d){
                            if(d.teacheerStatus=='0'){
                                return '未审核'
                            }else if(d.teacheerStatus=='1'){
                                return '通过'
                            }else if(d.teacheerStatus=='2'){
                                return '退回'
                            }else if(d.teacheerStatus=='8'){
                                return '不通过'
                            }else {
                                return''
                            }
                        }}
                    , {field: 'directorLeaderStatus', title: '学院教研主任审批状态',templet: function(d){
                            if(d.directorLeaderStatus=='0'){
                                return '未审核'
                            }else if(d.directorLeaderStatus=='1'){
                                return '通过'
                            }else if(d.directorLeaderStatus=='2'){
                                return '退回'
                            }else if(d.directorLeaderStatus=='8'){
                                return '不通过'
                            }else {
                                return''
                            }
                        }}
                    , {field: 'type', title: '操作', toolbar: '#barDemo'}
                ]]
                , page: true
                , parseData: function(res){ //res 即为原始返回的数据
                    if (res.flag != false) {
                        return {
                            "code": 0, //解析接口状态
                            "data": res.object,//解析数据列表
                            "count": res.totleNum, //解析数据长度
                            "msg": res.msg,
                        };
                    }else {
                        return{
                            "msg": res.msg
                        }
                    }
                }
            });

        form.on('radio(status)', function (data) {

            if(data.value=="1"||data.value=="0"){
                leaderStatus="1";
            }else {
                leaderStatus="0"
            }
            tableData.reload({
                where:{
                    status:data.value,
                    sDirectorLeaderStatus:leaderStatus,
                    deptId: $.cookie('deptId')
                }
            })
        });
        $.ajax({
            url: '/Meetequipment/getuser',
            type: 'get',
            dataType: 'json',
            success: function (res) {
                $('table').attr('id',res.object.userId)
                taId = res.object.userId;
            }
        })

        //查询
        $.ajax({
            url:'/rpmTopic/selectByparentNo',
            type: 'get',
            dataType: 'json',
            success:function (res) {
                var research = res.data.researchType
                var sectionType = res.data.sectionType
                var strs = ''
                var str = ''
                //研究领域
                for(var i=0;i<research.length;i++){
                    str += '<option value="' + research[i].dictNo + '">' +  research[i].dictName + '</option>'
                }
                //项目类别
                for(var i=0;i<sectionType.length;i++){
                    strs += '<option value="' + sectionType[i].dictNo + '">' +  sectionType[i].dictName + '</option>'
                }
                $('select[name="research"]').append(str)
                $('select[name="sectionType"]').append(strs);
                form.render('select');
            }
        })
        $('.search').click(function () {
            var teacheerStatus = $('input[name="status"]:checked').val();
            var research = $('select[name="research"]').val();
            var sectionType = $('select[name="sectionType"]').val();
            $.ajax({
                url:'/rpmTopic/selectByCondition?teacheerStatus='+teacheerStatus+'&sDirectorLeaderStatus='+leaderStatus+'&research='+research+'&sectionType='+sectionType+'&deptId='+$.cookie('deptId')+'&examineType='+"0",
                type: 'get',
                dataType: 'json',
                success:function (res) {
                    var msg = res.msg;
                    table.render({
                        elem: '#'+taId
                        ,url:''
                        ,data:res.object
                        , cols: [[
                            {type: 'checkbox', fixed: 'left'},
                            {field: 'planName', title: '计划名称'}
                            , {field: 'topicName', title: '项目名称'}
                            , {field: 'topicType', title: '项目类别',}
                            , {field: 'research', title: '研究领域'}
                            , {field: 'sDirectorLeaderStatus', title: '学校科研室主任审批状态',templet: function(d){
                                    if(d.sDirectorLeaderStatus=='0'){
                                        return '待批'
                                    }else if(d.sDirectorLeaderStatus=='1'){
                                        return '批准'
                                    }else{
                                        return '未批准'
                                    }
                                }}
                            , {field: 'sDirectorLeaderOpinion', title: '学校科研室主任审批意见'}
                            , {field: 'teacheerStatus', title: '学院老师审批状态',templet: function(d){
                                    if(d.teacheerStatus=='0'){
                                        return '待批'
                                    }else if(d.teacheerStatus=='1'){
                                        return '批准'
                                    }else{
                                        return '未批准'
                                    }
                                }}
                            , {field: 'teacheerOpinion', title: '学院老师审批意见'}
                            , {field: 'directorLeaderStatus', title: '学院教研主任审批状态',templet: function(d){
                                    if(d.directorLeaderStatus=='0'){
                                        return '待批'
                                    }else if(d.directorLeaderStatus=='1'){
                                        return '批准'
                                    }else{
                                        return '未批准'
                                    }
                                }}
                            , {field: 'directorLeaderOpinion', title: '学院教研主任审批意见'}
                            , {field: 'type', title: '操作', toolbar: '#barDemo'}
                        ]]
                        ,page: true //是否显示分页
                        ,limit: 10 //每页默认显示的数量
                        /*,done:function (res) {
                            debugger
                            if(res.data.length == 0){
                                $("#"+taId).next(".layui-form").find(".layui-none").html(msg);
                            }
                        }*/
                    });
                    if (res.flag) {
                        tableData.reload()
                        layer.closeAll();
                    }
                }
            })
        })

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            var text=$(this).text();
            var val = $(this).attr("value");
            if(obj.event === 'operate'){
                var teacheerStatus=''
                if(val=='1'){
                    teacheerStatus=1
                    layer.confirm('是否确认通过？', function (index) {
                        $.ajax({
                            url: '/rpmTopic/updateRpmTopic',
                            dataType: 'json',
                            type: 'get',
                            data:
                                 '&topicId=' + obj.data.topicId
                                +'&planId='+ obj.data.planId
                                +'&userId='+data.userId
                                +'&teacheerStatus='+teacheerStatus
                                +'&directorLeaderStatus='+'0',
                            success: function (res) {
                                if (res.flag) {
                                    tableData.reload()
                                    layer.close(index)
                                    layer.msg('操作成功！', {
                                        icon: 1,
                                        time: 1500
                                    });
                                }
                            }
                        })
                    })
                }else if(val=='2'){
                    teacheerStatus=2
                    layer.confirm('是否确认退回？', function (index) {
                        $.ajax({
                            url: '/rpmTopic/updateRpmTopic',
                            dataType: 'json',
                            type: 'get',
                            data:
                                 '&topicId=' + obj.data.topicId
                                +'&planId='+ obj.data.planId
                                +'&userId='+data.userId
                                +'&teacheerStatus='+teacheerStatus
                                + '&sDirectorLeaderStatus=' + '0',
                            success: function (res) {
                                if (res.flag) {
                                    tableData.reload()
                                    layer.close(index)
                                    layer.msg('操作成功！', {
                                        icon: 1,
                                        time: 1500
                                    });
                                }
                            }
                        })
                    })
                    }else {
                    teacheerStatus=8
                    layer.confirm('是否确认不通过？', function (index) {
                    $.ajax({
                        url: '/rpmTopic/updateRpmTopic',
                        dataType: 'json',
                        type: 'get',
                        data:
                             '&topicId=' + obj.data.topicId
                            +'&planId='+ obj.data.planId
                            +'&userId='+data.userId
                            +'&teacheerStatus='+teacheerStatus
                            + '&sDirectorLeaderStatus=' + '0',
                        success: function (res) {
                            if (res.flag) {
                                tableData.reload()
                                layer.close(index)
                                layer.msg('操作成功！', {
                                    icon: 1,
                                    time: 1500
                                });
                            }
                        }
                    })
                    })
                }
            }else {
                var userId = data.userId
                var planId = data.planId
                if(obj.event==="look")
                    $(this).attr('href', '/rpmPlan/reviewlook?type=2&userId=' + userId + '&planId=' + planId)
            }

        });
    });
</script>
